package com.miao.manage.web.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.miao.entity.TbItemParamItem;
import com.miao.service.TbItemParamItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping("/api/item/param/item")
@Controller
public class ApiItemParamItemController {

    @Autowired
    private TbItemParamItemService tbItemParamItemService;
    /**
     * 根据商品ID查询规格参数数据
     * @param itemId
     * @return
     */
    @RequestMapping(value = "{itemId}",method = RequestMethod.GET)
    public ResponseEntity<TbItemParamItem> queryItemParamItemById(@PathVariable("itemId") String itemId){
        try{
            EntityWrapper<TbItemParamItem> wrapper = new EntityWrapper<>();
            wrapper.where("item_id={0}",itemId);
            TbItemParamItem tbItemParamItem = tbItemParamItemService.selectOne(wrapper);
            if(null==tbItemParamItem){
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
            }
            return ResponseEntity.ok(tbItemParamItem);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
